package com.wy.web.old_contact;



import com.wy.pojo.Contact;
import com.wy.service.ContactService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/contact/findAll")
public class FindAllContactServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.调用service处理业务逻辑
        ContactService service = new ContactService();
        List<Contact> list = service.findAll();
        for (Contact contact : list) {
            System.out.println(contact);
        }
        //2.将查询结果存放到request对象中
        request.setAttribute("list",list);
        //3.请求转发到jsp页面
        request.getRequestDispatcher("/contact/list.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}